這篇要來實作兩個Container了,分別就是我們的
這兩個Container都有Official的在DockerHub上,因此我們只要很簡單的從DockerHub把他們Pull下來就可以,我們依序開始吧
# 載入openjdk
FROM openjdk:8-jdk-alpine
# 加入bash功能
RUN apk add --no-cache bash
# 將檢測MySQL是否Ready的腳本加入
COPY wait-for-it.sh /wait-for-it.sh
# 調整權限
RUN chmod +x /wait-for-it.sh
# 將目標WAR放入Docker Image中
ADD /target/mms.war .
# 此對外Port設定
EXPOSE 8090
version: '3.7'
# Service
services:
# Database MySQL
app-db:
image: mysql:8.0.17
container_name: app-db
#restart: always
volumes:
- mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: mms_db
MYSQL_USER: springboot
MYSQL_PASSWORD: springboot
ports:
- "3306:3306"
networks:
- app-server-network
# APP Server
app-server:
depends_on:
- app-db
image: mms/member-manage-system:0.0.1
build:
context: ./
dockerfile: Dockerfile
ports:
- "8090:8090"
environment: # Pass environment variables to the service
DATASOURCE_HOST: app-db
DATASOURCE_POST: 3306
DATASOURCE_NAME: mms_db
DATASOURCE_USERNAME: springboot
DATASOURCE_PASSWORD: springboot
networks:
- app-server-network
command: ["./wait-for-it.sh", "app-db:3306", "--", "java", "-jar", "mms.war"]
# Volume
volumes:
mysql-data:
# Network
networks:
app-server-network:
另外,也可以看看目前在docker裡的image、container、network、volume的狀況喔
參考資料、延伸閱讀:
下集預告:實作分享 - Jenkins